package leetcode.code1218;

import java.util.HashMap;
import java.util.Map;

public class Solution1 extends Solution1218 {

	@Override
	public int longestSubsequence(int[] arr, int difference) {
		Map<Integer, Integer> hash = new HashMap<>();
		int ans = 0;
		for (int cur : arr) {
			int find = cur - difference; // cur的左侧序列数
			int size = hash.getOrDefault(find, 0) + 1; // find的长度+1是cur的长度
			hash.put(cur, size);// 添加入表
			ans = Math.max(ans, size);// 更新最长子序列
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution1 so = new Solution1();
		so.debug1();
		so.debug2();
		so.debug3();

	}

}
